<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">

    <body>
        <ui:composition template="../templates/default3.xhtml">
            <ui:define name="content">
                <h:form id="payRMPO" binding="#{paymentManagerBean.loadPayRMPO}">
                    <p:panel header="Raw Material Purchase Order" id="rmpoPanel">
                        <table width="100%" border="0">
                            <tr>
                                <td width="200px">Delivery Date:</td>
                                <td>
                                    <h:outputText value="#{paymentManagerBean.selectedRawMaterialPurchaseOrder.deliveryDate}" >
                                        <f:convertDateTime pattern="dd-MMM-yyyy" timeZone="#{defaultManagerBean.tz}"/>
                                    </h:outputText>
                                </td>
                            </tr>
                            <tr>
                                <td>Purchasing Rep.:</td>
                                <td>
                                    <h:outputText value="#{paymentManagerBean.selectedRawMaterialPurchaseOrder.employee.name}" >
                                    </h:outputText>
                                </td>
                            </tr>
                            <tr>
                                <td>Supplier:</td>
                                <td>
                                    <h:outputText value="#{paymentManagerBean.selectedRawMaterialPurchaseOrder.supplier.company}" >
                                    </h:outputText>
                                </td>
                            </tr>
                            <tr>
                                <td>Amount to Pay:</td>
                                <td>
                                    <h:outputText value="#{paymentManagerBean.selectedRawMaterialPurchaseOrder.amountToPay}" >
                                        <f:convertNumber type="currency"/>
                                    </h:outputText>
                                </td>
                            </tr>
                            <tr>
                                <td>Status:</td>
                                <td>
                                    <h:outputText value="#{paymentManagerBean.selectedRawMaterialPurchaseOrder.status}" >
                                    </h:outputText>
                                </td>
                            </tr>
                        </table>
                    </p:panel>
                    <p:panel header="Material Requirement Plans" id="mrpPanel">
                        <p:dataTable id="mrPlans" var="mrplans" 
                                     value="#{paymentManagerBean.selectedRawMaterialPurchaseOrder.materialRequirementPlans}" 
                                     emptyMessage="No material requirement plans found with given criteria.">          
                            <p:column filterBy="#{mrplans.rawMaterial.name}" headerText="Raw Material Name" filterMatchMode="contains">  
                                <h:outputText value="#{mrplans.rawMaterial.name}" />  
                            </p:column> 
                            <p:column filterBy="#{mrplans.weight}" headerText="Required Amount (kg / litre)" filterMatchMode="contains">  
                                <h:outputText value="#{mrplans.weight}" />  
                            </p:column>
                            <p:column filterBy="#{mrplans.orderDate}" headerText="Date to Order" filterMatchMode="contains">  
                                <h:outputText value="#{mrplans.orderDate}" >
                                    <f:convertDateTime pattern="dd-MMM-yyyy" timeZone="#{defaultManagerBean.tz}"/>
                                </h:outputText>
                            </p:column>                        
                        </p:dataTable> 
                    </p:panel>
                    <p:panel header="Make Payment" id="makePaymentPanel">
                        <p:messages />
                        
                        <table width="100%" border="0">
                            <tr><td width="200px">Amount:</td>
                                <td>
                                    <p:inputText id="amountToPay" value="#{paymentManagerBean.amountToPayRMPO}" required="true"
                                                 requiredMessage="Amount to pay is required" label="Amount to Pay"
                                                 title="Amount to pay for the order."> 
                                        <f:convertNumber minFractionDigits="2" /> 
                                    </p:inputText>
                                    <font class="fieldNote">*</font>
                                </td>
                            </tr>
                            <tr>
                                <td></td>
                                <td>
                                    <p:commandButton id="btnMakePayment" value="Record Payment" 
                                                     title="Record payment for raw material purchase order." ajax="true"
                                                     update="makePaymentPanel"
                                                     actionListener="#{paymentManagerBean.makePayment}" /> 
                                </td>
                            </tr>
                        </table>
                    </p:panel>
                </h:form>
            </ui:define>
        </ui:composition>
    </body>
</html>
